import { Fragment } from '@/components/Fragment';
import { Button, ButtonGroup, Flex, View } from '@aws-amplify/ui-react';
import { Example, ExampleCode } from '@/components/Example';
import { ComponentClassTable } from '@/components/ComponentClassTable';
import StandardHTMLAttributes from '@/components/StandardHTMLAttributes.mdx';
import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay';
import ThemeExample from '@/components/ThemeExample.mdx';
import { ButtonDemo } from './demo';
import { IconButtonExample, ButtonThemeExample } from './examples';
## Demo
## Usage
Import the Button primitive and styles.
```jsx
import { Button } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
;
```
### onClick
Use the `onClick` prop to add a click handler to the Button.
```jsx
```
### Sizes
Use the `size` prop to change the Button size. Available options are `small`, `large`, and none (default).
```jsx
```
### Variations
Use the `variation` prop to change the Button variation. Available options are `primary`, `link`, `menu`, `warning`, `destructive` and none (default).
```jsx
```
### Icon buttons
Icons can be added to buttons and will adapt to the surrounding font-size.
```tsx file=./examples/iconButton.tsx
```
### Loading state
```jsx
```
### Other states
```jsx
```
### Accessibility
Setting an `aria-label` attribute for an icon Button:
```jsx
```
### ButtonGroup
Use a `ButtonGroup` to group buttons with the same `size` or `variation`.
```jsx
import { Button, ButtonGroup } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
// same size
;
// same variation
;
```
`ButtonGroup` is also a flex container, so any flex props can apply to it for layout purpose. See [Flex](/components/flex).
```jsx
import { Button, ButtonGroup } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
;
```
```jsx
```
## Customization
```tsx file=./examples/ButtonThemeExample.tsx
```
### Target classes
### CSS
To override styling on all Buttons, you can set the Amplify CSS variables or use the built-in `.amplify-button` class.
```css
/* styles.css */
[data-amplify-theme] {
--amplify-components-button-primary-background-color: #0057ff;
--amplify-components-button-primary-hover-background-color: #4d89fc;
}
/* OR */
.amplify-button {
background-color: #0057ff;
}
.amplify-button:hover {
background-color: #4d89fc;
}
```
To replace the Button styling, unset it:
```css
.amplify-button {
all: unset;
/* Add your styling here*/
}
```
### Local styling
To override styling on a specific Button, you can use (in order of increasing specificity): a class selector, data attributes, or style props.
_Using a class selector:_
```css
/* Example: class selector styling override */
.colorful-button {
background: linear-gradient(90deg, #fdbb2d 0%, #22c1c3 100%);
}
```
```jsx
import './styles.css';
;
```
_Using data attributes:_
```css
/* styles.css */
/* Override only primary variation styles */
.amplify-button[data-variation='primary'] {
background-color: teal;
color: white;
}
/* Override loading styles */
.amplify-button[data-loading='true'] {
opacity: 0.8;
}
/* Override disabled styles */
.amplify-button[disabled='true'] {
opacity: 0.8;
}
```
```jsx
import './styles.css';
```
_Using style props:_
```jsx
;
{
/* OR */
}
;
```